
//
//  NewFeatureCell.m
//  微博
//
//  Created by 沈艳男 on 15/11/29.
//  Copyright © 2015年 沈艳男. All rights reserved.
//

#import "NewFeatureCell.h"

@interface NewFeatureCell()
@property (nonatomic, strong) UIButton *startButton;

@end
@implementation NewFeatureCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUI];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        [self setUI];
    }
    return self;
}


// 设置控件
- (void)setUI
{
    [self.contentView addSubview:self.iconView];
    [self.contentView addSubview:self.startButton];
    
    self.startButton.hidden = YES;
    self.iconView.frame = self.bounds;
    self.startButton.translatesAutoresizingMaskIntoConstraints = NO;
    
    NSLayoutConstraint *startButtonConstraint1 = [NSLayoutConstraint constraintWithItem:self.startButton attribute:(NSLayoutAttributeCenterX) relatedBy:(NSLayoutRelationEqual) toItem:self attribute:(NSLayoutAttributeCenterX) multiplier:1 constant:0];
    NSLayoutConstraint *startButtonConstraint2 = [NSLayoutConstraint constraintWithItem:self.startButton attribute:(NSLayoutAttributeCenterY) relatedBy:(NSLayoutRelationEqual) toItem:self attribute:(NSLayoutAttributeCenterY) multiplier:1 constant:200];
    
    [self addConstraint:startButtonConstraint1];
    [self addConstraint:startButtonConstraint2];
}

- (UIButton *)startButton
{
    if (!_startButton) {
        UIButton *startButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [startButton setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:(UIControlStateNormal)];
        [startButton setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:(UIControlStateHighlighted)];
        [startButton addTarget:self action:@selector(startButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [startButton setTitle:@"立即体验" forState:(UIControlStateNormal)];
        _startButton = startButton;
    }
    return _startButton;
}

- (void)startButtonClick
{
    NSLog(@"startButtonClick");
}

- (void)showStartButton
{
    self.startButton.hidden = NO;
    self.startButton.transform = CGAffineTransformMakeScale(0, 0);
    [UIView animateWithDuration:1.25 delay:0.0 usingSpringWithDamping:0.25 initialSpringVelocity:9 options:0 animations:^{
        self.startButton.transform = CGAffineTransformIdentity;
    } completion:^(BOOL finished) {
    }];
}

- (void)hiddenstartButton
{
    self.startButton.hidden = YES;
}

- (UIImageView *)iconView
{
    if (!_iconView) {
        UIImageView *iconView = [[UIImageView alloc] init];
        _iconView = iconView;
    }
    return _iconView;
}

@end
